/*************************************************************************
	> File Name: oj-216_names_sort.c
	> Author: Wang Bo
	> Mail: 1276106221@qq.com
	> Created Time: 2020年10月27日 星期二 02时53分49秒
 ************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student {
    char gender[2];
    char name[47];
} STU;

void sort(STU **stus, int n) {
    for (int i = 0; i < n; ++i) {
        for (int j = i - 1; j >= 0; --j) {
            char *ln = stus[j]->name;
            char *rn = stus[j + 1]->name;
            if (strcmp(ln, rn) > 0) {
                STU *temp = stus[j];
                stus[j] = stus[j + 1];
                stus[j + 1] = temp;
            } else break;
        }
    }
}

int main() {
    int n;
    scanf("%d", &n);
    getchar();
    STU **stus = (STU **)malloc(sizeof(STU *) * n);
    for (int i = 0; i < n; ++i) {
        stus[i] = (STU *)malloc(sizeof(STU));
        scanf("%[^.]", stus[i]->gender);
        getchar();
        scanf("%s", stus[i]->name);
        getchar();
        //scanf("%s.%s", stus[i]->gender, stus[i]->name);
    }
    sort(stus, n);
    for (int i = 0; i < n; ++i) {
        printf("%s\n", stus[i]->name);
        free(stus[i]);
    }
    free(stus);
    return 0;
}
